<template>
  <div>
    <h2>我是首页组件</h2>
    <h2>这是首页</h2>
    <nav>
      <router-link to="/home/news">新闻</router-link>
      <router-link to="/home/weather">天气</router-link>
    </nav>
    <router-view/>
  </div>
</template>

<script>
  export default {
    data(){
      return{
        //后期案列中不会这样使用，而回操作currentIndex来记录
        path:"/home/news",
      }
    },
    //组件内守护方法，离开组件前，保存当前活动的路由路径
    beforeRouteLeave(to,from,next){
      this.path=this.$route.path;
      next();
    },
    //声明周期函数，当组件再次被激活事，修改路由
    activated() {
      this.$router.push(this.path)
    }
  }
</script>